// pages/evaluate/evaluate.js
var ports = require("../../utils/ports.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsId:'',
    goodsName:'',
    advice: '',
    flag: false,
    images: []
  },
  onLoad(e){
    var goodsId= e.id
    var goodsName = e.name
    this.setData({
      goodsId: goodsId,
      goodsName: goodsName
    })
  },
  inputAdvice(e) {
    this.setData({
      advice: e.detail.value
    })
  },
  submit() {
    var imagearr = []
    for(var i=0;i<this.data.images.length;i++){
      var imgs = this.data.images[i]
      var ingurl = imgs.url
      imagearr.push(ingurl)
    }
    let that = this
    if (!that.data.advice.trim()) {
      wx.showToast({
        title: '请填写评价内容',
        icon: 'none'
      })
      return
    }
    wx.showToast({
      title: '提交中',
      icon: 'loading',
      mask: true
    })
    let data = {}
    var sessionID = wx.getStorageSync('USER_SESSIONID')
    data.sessionID = sessionID
    data.memberOrderGoodsID = that.data.goodsId,
    data.content = that.data.advice
    ports.ModuleFeed.discussMemberOrderGoods(data, that, res => {
      wx.hideToast()
      // console.log(res)
      if (res.data.header.code == 0) {
        wx.showToast({
          title: res.data.header.msg,
          icon: 'none'
        })
        wx.navigateBack()
      } else {
        wx.showToast({
          title: res.data.header.msg,
          icon: 'none'
        })
      }
    })
  },
  //改变图片
  changeImg(e) {
    this.setData({
      images: e.detail.image
    })
  },
  //删除图片
  delImg(e) {
    if (e.detail.currentIndex == 0) {
      this.setData({
        images: e.detail.image
      })
    }
  },
})